let arr = [2, 0, 2, 1, 8, 7, 0, 3, 6, 1, 9];

let shellSort = arr => {
    let len = arr.length;
    let increment = len;
    while (true) {
        increment = Math.floor(increment / 2);
        for (let k = 0; k < increment; k++) {
            // 执行插入排序
            for (let i = k + increment; i < len; i += increment) {
                for (let j = i; j > k; j -= increment) {
                    if (arr[j] < arr[j - increment]) {
                        [arr[j], arr[j - increment]] = [arr[j - increment], arr[j]];
                    } else { // 不需要交换
                        break;
                    }
                }
            }
        }
        if (increment === 1) break;
    }
    return arr;
}

console.log(shellSort(arr))